package de.tabuma.soapforms.soapproject.controller;

import de.tabuma.soapforms.*;
import de.tabuma.lib.tabumacontroller;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import de.tabuma.customer.entity.*;
import de.tabuma.customer.logik.*;
import com.google.appengine.api.users.*;
import de.tabuma.soapforms.soapproject.view.*;

/**
 *
 * @author alefen
 */
public class controller extends tabumacontroller {

    private static Logger log = Logger.getLogger(controller.class.getName());

    public controller(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        List<Customer> cList = CustomerFacade.getCustomer(user.getEmail());
        request.setAttribute(constants.customerList, cList);

        boolean in = false;

        if(request.getParameter(constants.addSoapProject)!=null) {
            create create = new create(this.getServlet(), this.getParameter());
            create.navigate(context, request, response, out);
            in = true;
        }

        if(request.getParameter(constants.addSoapProject1)!=null) {
            create1 create1 = new create1(this.getServlet(), this.getParameter());
            create1.navigate(context, request, response, out);
            in = true;
        }

        if(request.getParameter(constants.addSoapProject2)!=null) {
            create2 create2 = new create2(this.getServlet(), this.getParameter());
            create2.navigate(context, request, response, out);
            in = true;
        }

        if(request.getParameter(constants.updateSoapProject)!=null) {
            update update = new update(this.getServlet(), this.getParameter());
            update.navigate(context, request, response, out);
            in = true;
        }

        if(request.getParameter(constants.updateSoapProject1)!=null) {
            update update = new update(this.getServlet(), this.getParameter());
            update.navigate(context, request, response, out);
            in = true;
        }

        if(request.getParameter(constants.removeSoapProject)!=null) {
            remove remove = new remove(this.getServlet(), this.getParameter());
            remove.navigate(context, request, response, out);
            in = true;
        }

        if(request.getParameter(constants.removeSoapProject1)!=null) {
            remove remove = new remove(this.getServlet(), this.getParameter());
            remove.navigate(context, request, response, out);
            in = true;
        }

        if(!in) {
            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);
        }

        view view = new view(this.getServlet(), this.getParameter());
        view.processRequest(context, request, response, out);
    }
}
